<extend name="common:commonTemplate" />
<block name="main_content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="index.html"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">商品</a> <a class="current" href="#">sku信息列表</a>
		</div>
		
	</div>
	<div class="container-fluid">
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
						<h5>搜索条件</h5>
					</div>
					<div class="widget-content nopadding">
						<form novalidate="novalidate" id="basic_validate"
							name="basic_validate" action="#" method="post"
							class="form-horizontal">
							<div class="control-group">
								<label class="control-label">商品编码</label>
								<div class="controls">
									<input type="text" id="style_sn" name="style_sn">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">商品名称</label>
								<div class="controls">
									<input type="text" id="style_name" name="style_name">
								</div>
							</div>
							<div class="control-group">
								<label class="control-label">英雄会项目中是否可购买</label>
								<div class="controls">
					                <select style="width:220px;" id="is_buy_fz">
					                  <option value="1">是</option>
					                  <option value="0">否</option>
					                  <option value="">所有</option>
					                </select>
					           </div>
							</div>
							<div class="form-actions">
								<input id="btn_search" type="button" class="btn btn-success" value="搜索">
								<input id="btn_add" style="background:red" onclick="location.href='/sku/addSku" type="button" class="btn btn-success" value="新增">
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	
		<div class="row-fluid">
      <div class="span12">
        <div class="widget-box">
          <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
            <h5>搜索结果</h5>
          </div>
          <div class="widget-content nopadding">
            <table id="search_result" page_index="1" class="table table-bordered table-striped">
              <thead>
                <tr>
                  <th>sku_id</th>
                  <th>sku_sn</th>
                  <th>sku_name</th>
                  <th>商品编码</th>
                  <th>商品名称</th>
                  <th>淘宝style_id</th>
                  <th>淘宝style_name</th>
                  <th>淘宝分类id</th>
                  <th>市场价</th>
                  <th>单价</th>
                  <th>英雄会项目中是否可购买</th>
                  <th>状态</th>
                  <th>操作</th>
                </tr>
              </thead>
              <tbody>
              </tbody>
            </table>
          </div>
          
        </div>
        
        <div id="paging" class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix">
        	<div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="DataTables_Table_0_paginate">
        		<a page_index="1" class="first ui-corner-tl ui-corner-bl fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_first">首页</a>
        		<a class="previous fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_previous">上页</a>
        		<span>共<span id="total_count">0</span>条 <span id="curr_page_index">0</span>/<span id="total_page">0</span></span>
       			<a class="next fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_next">下页</a>
       			<a class="last ui-corner-tr ui-corner-br fg-button ui-button ui-state-default" tabindex="0" id="DataTables_Table_0_last">末页</a>
       			<span>
        			<span><input type="text" style="width:20px;" class="ui-state-default"></span>
        			
        			<a class="fg-button ui-button ui-state-default" tabindex="0">跳转</a>
       			</span>
       		</div>
    	</div>
        

      </div>
    </div>
	
	</div>



</div>
</block>

<block name="js_content">
<script>
	SkuListPage = {
			'BindEvent': function(){
				$('#btn_search').bind('click', function(){
					var page_index = 1;
					SkuListPage.Search(page_index);
				});
				$(".first,.previous,.last,.next").bind('click', function(){
					if($(this).hasClass('ui-state-disabled')){
						return false;
					}
					var page_index = $(this).attr('page_index');
					if(page_index == undefined){
						page_index = 1;
					}
					SkuListPage.Search(page_index);
				});
			},
			'Search': function(page_index){
				var style_sn		= $('#style_sn').val();
				var style_name		= $('#style_name').val();
				var is_buy_fz		= $('#is_buy_fz').val();
				var page_size		= 10;
				var result = SkuService.SearchSkuList(style_sn, style_name,is_buy_fz,page_index, page_size);
				if(result.IsSuccess == 0){
					alert(result.ErrorMsg);
					return;
				}
				else{
					SkuListPage.FillTable(result.Result.lst_sku_en, page_index);
					SkuListPage.SetPageIndex(result.Result.total_page, result.Result.total_count, page_index);
				}
			},
			'FillTable': function(lst_sku_en, page_index){
				var html_array = new Array();
				if(lst_sku_en.length > 0){
					for(var index in lst_sku_en){
						var sku_en = lst_sku_en[index];
						html_array.push('<tr class="odd gradeX">');
						html_array.push('<td>' + sku_en.sku_id + '</td>');
						html_array.push('<td>' + sku_en.sku_sn + '</td>');
						html_array.push('<td>' + sku_en.sku_name + '</td>');
						html_array.push('<td>' + sku_en.style_sn + '</td>');
						html_array.push('<td>' + sku_en.style_name + '</td>');
						html_array.push('<td>' + sku_en.taobao_style_id + '</td>');
						html_array.push('<td>' + sku_en.taobao_style_name + '</td>');
						html_array.push('<td>' + sku_en.taobao_category_id + '</td>');
						html_array.push('<td>' + sku_en.market_price + '</td>');
						html_array.push('<td>' + sku_en.sale_price + '</td>');
						html_array.push('<td>' + sku_en.is_buy_fz_text + '</td>');
						html_array.push('<td>' + sku_en.status_text + '</td>');
						html_array.push('<td><div style="text-align:center;"><a style="color:blue;" href="/sku/detail?sku_id=' + sku_en.sku_id + '">查看详情</a></div></td>');
						html_array.push('</tr>');
					}
				}
				else{
					html_array.push('<td style="text-align:center" colspan="10">没查到数据</td>');
				}
				
				var html = html_array.join('\r\n');
				$('#search_result tbody').html('');
				$('#search_result tbody').html(html);
				
				$('#search_result').attr('page_index', page_index);;
			},
			'SetPageIndex': function(total_page, total_count, page_index){
				$('#total_count').text(total_count);
				$('#total_page').text(total_page);
				$('#curr_page_index').text(page_index);
				page_index = parseInt(page_index);
				
				if(page_index == 1){
					$('#paging .first').addClass('ui-state-disabled');
					$('#paging .previous').addClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', 1);
				}
				else{
					$('#paging .first').removeClass('ui-state-disabled');
					$('#paging .previous').removeClass('ui-state-disabled');
					$('#paging .first').attr('page_index', 1);
					$('#paging .previous').attr('page_index', page_index - 1);
				}
		
				if(total_page == page_index){
					$('#paging .last').addClass('ui-state-disabled');
					$('#paging .next').addClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', total_page);
				}
				else{
					$('#paging .last').removeClass('ui-state-disabled');
					$('#paging .next').removeClass('ui-state-disabled');
					$('#paging .last').attr('page_index', total_page);
					$('#paging .next').attr('page_index', page_index + 1);
				}
				
			},
			
	};


	$(document).ready(function(){
		SkuListPage.BindEvent();
	});
</script>
</block>